package com.moyun.finance.service;

import com.moyun.finance.entity.OrgDept;
import com.moyun.finance.entity.OrgRole;
import com.moyun.finance.entity.Response;
import com.moyun.finance.repository.OrgDeptRepository;
import com.moyun.finance.repository.OrgRoleRepository;
import com.moyun.finance.utils.BaseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrgRoleService {
    @Autowired
    OrgRoleRepository orr;

    public Response save(OrgRole role){
        role.setId(BaseUtil.uuid());
        orr.save(role);
        return new Response("添加成功!",true);
    }

    public Response update(OrgRole role){
        orr.save(role);
        return new Response("部门信息修改成功!",true);
    }

    public Response delete(OrgRole role){
        orr.delete(role);
        return new Response("部门删除成功",true);
    }

    //本公司所有角色
    public List<OrgRole> findAll(String companyId){
        List<OrgRole> roles =  orr.findByCompanyId(companyId);
        return roles;
    }

    public OrgRole findOneById(String deptId){
        return orr.findById(deptId).orElse(null);
    }
}
